package com.xbts.system.domain;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.xbts.common.annotation.Excel;
import com.xbts.common.core.domain.BaseEntity;
import com.xbts.common.enums.ShoppingCarEnums;
import com.xbts.common.utils.StringUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.Objects;

/**
 * 用户发票信息对象 cnInvoiceManagement
 *
 * @author xbts
 * @date 2023-08-03
 */
@Data
@ApiModel("用户发票信息对象")
@TableName("cn_invoice_management")
public class CnInvoiceManagement extends BaseEntity {

    private static final long serialVersionUID=1L;

    /** 发票主键 */
    @TableId
    @JsonSerialize(using= ToStringSerializer.class)
    private Long invoiceManagementId;

    /** 用户id*/
    @Excel(name = "用户id")
    @ApiModelProperty("用户id")
    @JsonSerialize(using= ToStringSerializer.class)
    private Long userId;

    /** 支付编号*/
    @Excel(name = "支付编号")
    @ApiModelProperty("支付编号")
    @JsonSerialize(using= ToStringSerializer.class)
    private String orderItemId;

    /** 票据类型  增值税普通发票：1 增值税专用发票:2 */
    @Excel(name = "票据类型")
    @ApiModelProperty("票据类型")
    @NotEmpty(message = "票据类型不能为空")
    private String feesType;

    /** 票据摘要 */
    @Excel(name = "票据摘要")
    @ApiModelProperty("票据摘要")
    private String feesSummary;

    /** 数额 */
    @Excel(name = "开票金额")
    @ApiModelProperty("开票金额")
    private Double amount;

    /** 支付时间 */
    @Excel(name = "支付时间")
    @ApiModelProperty("支付时间")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date paymentTime;

    /** 发票状态 */
    @Excel(name = "发票状态",readConverterExp = "status=1 开票中，status=2 已开票")
    @ApiModelProperty("发票状态 （status=1 开票中，status=2 已开票。)")
    private String invoiceStatus;

    /**开票日期*/
    @Excel(name = "开票日期")
    @ApiModelProperty("开票日期")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date invoiceDate;

    /**发票编号*/
    private String invoiceNumber;

    /**票据内容 */
    private String invoiceContent;

    /**订单所属人员 */
    private String nickName;

    /**发票经手人员 */
    private String invoiceHandlingPersonnel;

    /** 附件地址 */
    private String fileUrl;

    /** 发票详情对象ID  */
    private String invoiceInformationId;


    private String orderItemSn;
    /** 购物车类型(CLOUD_SERVER云服务器 MARKET_CLOUD市场云 GOV_CLOUD政务云) */
    @ApiModelProperty("购物车类型(CLOUD_SERVER云服务器 MARKET_CLOUD市场云 GOV_CLOUD政务云)")
    private ShoppingCarEnums shoppingCarEnums;

    /** 发票详情对象 */
    @TableField(exist = false)
    private SysUserInvoiceInformation sysUserInvoiceInformation = new SysUserInvoiceInformation();
    @TableField(exist = false)
    private ShoppingCarEnums type;

    public<T> QueryWrapper<T> queryWrapper(){
        QueryWrapper<T> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq(!Objects.isNull(userId),"userId",userId);
        queryWrapper.like(StringUtils.isNotEmpty(feesType),"fees_type",feesType);
        queryWrapper.like(StringUtils.isNotEmpty(feesSummary),"fees_summary",feesSummary);
        queryWrapper.eq(!Objects.isNull(amount),"amount",amount);
        return queryWrapper;
    }
}